Skip to content

Conversation

@mjohanse-emr
Copy link
Contributor

@mjohanse-emr mjohanse-emr commented Jul 31, 2025

What does this Pull Request accomplish?

Adds a DateTimeConverter class that converts python datetime.datetime objects to protobuf timestamp_pb2.Timestamp objects. I put this converter in builtin.py since we do not own either type. They are included as built-in types for python/protobuf.

timestamp_pb2.Timestamp has ToDatetime and FromDatetime functions which make this conversion easy.

Once we add converters for hightime.datetime and/or bintime.DateTime, we'll have to update the python type checking logic to differentiate between these three different "datetime" types. I'm not including any of that logic in this PR.

Why should this Pull Request be merged?

Implements part of AB#3166769

What testing has been done?

Unit tests, mypy, pyright, styleguide

I ran the all_types example and this is what shows up for datetime:
image

@github-actions
Copy link
Contributor

github-actions bot commented Jul 31, 2025

Test Results

   10 files  ± 0     10 suites  ±0   21s ⏱️ ±0s
  224 tests + 3    224 ✅ + 3  0 💤 ±0  0 ❌ ±0 
2 190 runs  +30  2 190 ✅ +30  0 💤 ±0  0 ❌ ±0 

Results for commit 1f08864. ± Comparison against base commit 2e9b3ba.

This pull request removes 29 and adds 32 tests. Note that renamed tests count towards both.
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object10-Collection.bool]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object11-Collection.bytes]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object12-Collection.float]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object13-Collection.int]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object14-Collection.str]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object15-Collection.bool]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object16-Collection.bytes]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object17-Collection.float]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object18-Collection.int]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object19-Collection.str]
…
tests.unit.test_convert ‑ test___python_datetime_datetime___to_any___valid_timestamppb2_value
tests.unit.test_convert ‑ test___timestamppb2_timestamp___from_any___valid_python_value
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object10-datetime]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object11-Collection.bool]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object12-Collection.bytes]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object13-Collection.float]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object14-Collection.int]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object15-Collection.str]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object16-Collection.bool]
tests.unit.test_convert ‑ test___various_python_objects___get_best_matching_type___returns_correct_type_string[python_object17-Collection.bytes]
…

♻️ This comment has been updated with latest results.

Signed-off-by: Michael Johansen <[email protected]>
@mjohanse-emr mjohanse-emr marked this pull request as ready for review July 31, 2025 15:46
Michael Johansen added 2 commits July 31, 2025 13:26
@mjohanse-emr mjohanse-emr merged commit 70cce60 into main Jul 31, 2025
14 checks passed
@mjohanse-emr mjohanse-emr deleted the users/mjohanse/timestamp_converter branch July 31, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants